<?php
namespace Home\Controller;
use Think\Controller;
class LoginController extends CommonController {
	/**
	 * [index 用户访问的页面，跳转过去微信网页授权]
	 * @Author   Xuebingsi
	 * @DateTime 2017-02-08T11:59:00+0800
	 * @return   [type]                   [description]
	 */
    public function index(){

    	$return_url = "http://1o533n8683.imwork.net/P201606/weixin/api.php/home/login/callback";
    	$url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=".APPID."&redirect_uri=". urlencode($return_url)."&response_type=code&scope=snsapi_base&state=123#wechat_redirect 
    	";

    	$url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=".APPID."&redirect_uri=". urlencode($return_url)."&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect 
    	";

    	header("Location:".$url);

    }
    /**
     * [callback 微信授权回调地址]
     * @Author   Xuebingsi
     * @DateTime 2017-02-08T11:58:24+0800
     * @return   function                 [description]
     */
    public function callback()
    {
    	$code = $_GET['code'];

    	$url ="https://api.weixin.qq.com/sns/oauth2/access_token?appid=".APPID."&secret=".APPSECRET."&code=".$code."&grant_type=authorization_code";

    	$res = $this->wget($url);

    	$access_token = $res['access_token'];
    	$openid = $res['openid'];
    	$url = "https://api.weixin.qq.com/sns/userinfo?access_token=".$access_token."&openid=".$openid."&lang=zh_CN";

    	$res = $this->wget($url);

    	var_dump($res);

    }
}